package com.lujianfei.redpacketstat.database.dao

import androidx.lifecycle.LiveData
import androidx.room.*
import com.lujianfei.redpacketstat.database.bean.RedPacketEntity
import com.lujianfei.redpacketstat.database.bean.UserEntity


@Dao
interface UserDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(vararg userEntities: UserEntity): LongArray

    @Update(onConflict = OnConflictStrategy.REPLACE)
    fun update(vararg userEntities: UserEntity)

    @Delete
    fun delete(vararg userEntities: UserEntity)

    @Query("SELECT * FROM user where id = :id")
    fun queryById(id: Int): UserEntity?

    @Query("SELECT * FROM user")
    fun queryAllWithLiveData(): LiveData<MutableList<UserEntity>>

    @Query("SELECT * FROM user")
    fun queryAll(): MutableList<UserEntity>

    @Query("SELECT * FROM user WHERE status = :status")
    fun queryAllByStatus(status:Int): LiveData<MutableList<UserEntity>>

    @Query("SELECT COUNT(*) FROM user WHERE status = :status")
    fun queryCountByStatus(status:Int): Int
}